package io.gitee.yxsnake.framework.web.core;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.servlet.LocaleResolver;

import java.util.Locale;


/**
 * @author snake
 * @description 获取请求头国际化信息
 * @since 2024/11/2 22:14
 */
public class I18nLocaleResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(@NotNull HttpServletRequest httpServletRequest) {
        String language = httpServletRequest.getHeader("content-language");
        Locale locale = Locale.getDefault();
        if (language != null && !language.isEmpty()) {
            String[] split = language.split("_");
            locale = Locale.of(split[0],split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(@NotNull HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}